package ModelLayer;
import java.util.ArrayList;

/**
 * Delordre
 * 
 * @author (dmab0913 Gruppe4) 
 * @version (a version number or a date)
 */
public class PartOrderContainer
{
    private ArrayList<PartOrder> PartOrder;
    private static PartOrderContainer instance;   

    public PartOrderContainer()
    {
        PartOrder = new ArrayList<PartOrder>();
    }

    /**
     * Singleton for the PartOrderContainer class
     */
    public static PartOrderContainer getInstance()
    {
        if (instance == null)
        {
            instance = new PartOrderContainer();
            return instance;
        }
        return instance;
    }

    /**
     * adds a partorder to the order
     */
    public void addPartOrder(PartOrder partOrder)
    {
        PartOrder.add(partOrder);
    }

    /**
     * finds a specific partorder-object from the order
     */
    public PartOrder findPartOrder(long orderNumber2)
    {
        int index = 0;
        boolean found = false;
        while(index < PartOrder.size() && !found)
        {
            PartOrder P = PartOrder.get(index);
            if(orderNumber2 == P.getOrderNumber2())
            {
                found = true;
            }
            else
            {
                index++;
            }
        }

        if(found)
        {
            return PartOrder.get(index);
        }
        else
        {
            return null;
        }
    }

    /**
     * finds and updates all the fields of a Partorder-object except for orderNumber
     */
    public void updatePartOrder( long orderNumber2, String description2, int quantity2)
    {
        boolean found = false;
        int index = 0;
        while(index < PartOrder.size() && !found)
        {
            PartOrder P = PartOrder.get(index);
            if(P.getOrderNumber2() == orderNumber2)
            {
                P.updatePartOrder(orderNumber2, description2, quantity2);
                found = true;
            }
            index++;
        }
    }    
}
